<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2016-12-01
 * Time: 18:10
 */

namespace Shop\Api;


use Common\Api\Api;
use Shop\Model\CategoryLangModel;

class CategoryLangApi extends Api
{
    public function _init()
    {
        $this->model = new CategoryLangModel();
    }


    public function addCateLang($cate_id,$langs,$langs_value){
        $allEntity = [];
        for($i=0; $i<count($langs) ;$i++){
            array_push($allEntity,[
                'cate_id'=>$cate_id,
                'lang'=>$langs[$i],
                'name'=>$langs_value[$i]
            ]);
        }
        $result = $this->getModel()->addAll($allEntity);

        return $result;
    }

    public function updateCateLang($cate_id,$langs,$langs_value){
        $map['cate_id'] = $cate_id;

        $this->getModel()->where($map)->delete();

        return $this->addCateLang($cate_id,$langs,$langs_value);
    }
}